package com.baidu.service.impl;

import com.baidu.service.UploadSrvice;
import com.baidu.utils.OssUploadTemplate;
import com.baidu.utils.ResultResponse;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author 满天星斗
 * @version 1.0
 * @description: TODO
 * @date 2021/8/18 19:17
 */
@Service
public class UploadServiceImpl implements UploadSrvice {

    @Resource
    private OssUploadTemplate uploadTemplate;


    @Override
    public ResultResponse upload(HttpServletRequest request) {
        MultipartFile file = ((MultipartHttpServletRequest)request).getFile("file");
        return uploadTemplate.uploadFileObjectStorage(file);
    }

    @Override
    public ResultResponse delFile(String filename) {
        return uploadTemplate.deleteFileObjectStorage(filename);
    }

    @Override
    public ResultResponse downLoadFile(String filename) {
        return uploadTemplate.downloadObjectStorage(filename);
    }


}
